package cn.itcast.wanxinp2p.consumer.service.iml;

import cn.itcast.wanxinp2p.api.account.model.AccountDTO;
import cn.itcast.wanxinp2p.api.account.model.AccountRegisterDTO;
import cn.itcast.wanxinp2p.common.domain.RestResponse;
import cn.itcast.wanxinp2p.consumer.agent.AccountApiAgent;
import cn.itcast.wanxinp2p.consumer.service.AccountInforRegisterTCC;
import org.dromara.hmily.annotation.Hmily;
import org.springframework.beans.factory.annotation.Autowired;

public class AccountInforRegisterTCCImpl implements AccountInforRegisterTCC {

  @Autowired
  private AccountApiAgent accountApiAgent;

    @Hmily(cancelMethod = "rollback",confirmMethod = "commit")
    @Override
    public void prepare(AccountRegisterDTO accountRegisterDTO) {
        RestResponse<AccountDTO> register = accountApiAgent.register(accountRegisterDTO);
        Long id = register.getResult().getId();
        if(id==null){
            throw new RuntimeException("统一账户 。。。。。。。。。。。注册账号保存失败");
        }
    }

    @Override
    public void commit(AccountRegisterDTO accountRegisterDTO) {


    }


    @Override
    public void rollback(AccountRegisterDTO accountRegisterDTO) {
        accountApiAgent.register(accountRegisterDTO);
    }
}
